<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <title>CardEcho Manage</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <link rel="stylesheet" href="__STATIC__/lib/layuiadmin/layui/css/layui.css" media="all">
    <link rel="stylesheet" href="__STATIC__/lib/layuiadmin/style/admin.css" media="all">
    <link rel="stylesheet" href="__STATIC__/lib/layuiadmin/style/login.css" media="all">
</head>

<body>

    <div class="layadmin-user-login layadmin-user-display-show" id="LAY-user-login" style="display: none;">

        <div class="layadmin-user-login-main">
            <div class="layadmin-user-login-box layadmin-user-login-header">
                <h2>CardEcho</h2>
            </div>
            <div class="layadmin-user-login-box layadmin-user-login-body layui-form">
                <form class="layui-form">

                    <div class="layui-form-item">
                        <label class="layadmin-user-login-icon layui-icon layui-icon-username" for="LAY-user-login-username"></label>
                        <input type="text" name="username" id="username" value="" id="LAY-user-login-username" lay-verType="tips"
                               lay-verify="required_en" placeholder="{:lang('Username')}" class="layui-input" maxlength="30">
                    </div>
                    <div class="layui-form-item">
                        <label class="layadmin-user-login-icon layui-icon layui-icon-password" for="LAY-user-login-password"></label>
                        <input type="password" name="password"  value="" id="LAY-user-login-password" lay-verType="tips"
                               lay-verify="required_en" placeholder="{:lang('Password')}" class="layui-input" maxlength="30">
                    </div>
                    <div class="layui-form-item check_email" style="display: none">
                        <div class="layui-row">
                            <div class="layui-col-xs7">
                                <label class="layadmin-user-login-icon layui-icon layui-icon-vercode" for="LAY-user-login-vercode"></label>
                                <input type="text" name="vercode" id="vercode" value=""  lay-verType="tips" placeholder="{:lang('vercode')}" class="layui-input" maxlength="6">
                            </div>
                            <div class="layui-col-xs5">
                                <div style="margin-left: 10px;">
                                    <button type="button" class="layui-btn layui-btn-fluid" id="getsmscode">Send Code</button>
                                </div>
                            </div>
                        </div>
                    </div>
                    <div class="layui-form-item" id="captcha_div">
                        <div class="layui-row">
                            <div class="layui-col-xs7">
                                <label class="layadmin-user-login-icon layui-icon layui-icon-vercode" for="LAY-user-login-vercode"></label>
                                <input type="text" name="captcha" id="captcha_ipt" value=""  lay-verType="tips"
                                lay-verify="required_en" placeholder="{:lang('captcha')}" class="layui-input" maxlength="4">
                            </div>
                            <div class="layui-col-xs5">
                                <div style="margin-left: 10px;">
                                    <img src="{:url('verify/index')}" id="captcha_img" onclick="setCaptcha()" title="{:lang('change vercode')}" alt="captcha" style="max-width:120px;cursor:pointer;" />
                                </div>
                            </div>
                        </div>
                    </div>

                    <div class="layui-form-item">
                        <button class="layui-btn layui-btn-fluid" lay-submit lay-filter="password_login">{:lang('Sign in')}</button>
                    </div>
                </form>
            </div>
        </div>

        <div class="layui-trans layadmin-user-login-footer">
            <p>Copyright © 2021 CardEcho v1.0</p>
        </div>
    </div>

    <script src="__STATIC__/lib/layuiadmin/layui/layui.js"></script>
    <script src="__STATIC__/js/jquery.min.js" type="text/javascript" charset="utf-8"></script>
    <script src="__STATIC__/js/shop.js"></script>
    <script>
        layui.config({
            base: '__STATIC__/lib/layuiadmin/' //静态资源所在路径
        }).extend({
            index: 'lib/index' //主入口模块
        }).use(['index', 'form'], function() {
            var $ = layui.$,
                setter = layui.setter,
                admin = layui.admin;

            //用户过期后，重定向全屏处理
            if (window != top) top.location.href = location.href;

            var form = layui.form;
            form.render();

            //提交
            form.on('submit(password_login)', function(data) {
                JsPost("{:url('login/checkLogin')}", data.field, function(data){
                    if(data.code == 0){
                        layer.msg('{:lang("login_success")}');
                        setTimeout("window.location.href='" + data.data.href + "'; ", 1500);
                    }else if(data.code == 2){
                        $(".check_email").show();
                        setCaptcha();
                    } else {
                        // if (data.code == '10013' || data.code == '10012') {
                        //     $('#captcha_div').show();
                        // }
                        setCaptcha();
                        layer.msg(data.msg);
                    }
                });
                return false;
            });

            //更改验证码图片
            setCaptcha = function() {
                $('#captcha_ipt').val("");
                var timestamp = new Date().getTime();
                $('#captcha_img').attr('src', '{:url(\'verify/index\')}?' + timestamp);
            }

            var getCode = document.getElementById('getsmscode');
            var wait = 60;
            function time(btn){
                if (wait===0) {
                    getCode.removeAttribute("disabled");
                    getCode.innerHTML = "Send Code";
                    wait = 60;
                }else{
                    getCode.setAttribute("disabled",true);
                    getCode.innerHTML = "<font color='black'>" + wait + " </font> Resend after";
                    wait--;
                    setTimeout(function(){
                        time(btn);
                    },1000);
                }
            }
            getCode.onclick = function(){
                const username = $("#username").val();
                const loading =parent.layer.load(1, {shade: [0.1,'#fff']});
                $.post("{:url('login/emailSend')}", {username:username}, function (res) {
                    parent.layer.close(loading);
                    if (res.code > 0) {
                        time(this);
                        layer.msg('The verification code has been sent, please wait patiently.', {time: 1500, icon: 1});
                        $("#getsmscode").attr('disabled' , 'disabled');
                        setCaptcha();
                    } else {
                        layer.msg(res.msg,{icon: 5, time: 1500});
                    }
                });
            };

        });
    </script>

    <script>
        var _hmt = _hmt || [];
        (function() {
            var hm = document.createElement("script");
            hm.src = "https://hm.baidu.com/hm.js?664fcbcf82c2ad71554e315b29748ed0";
            var s = document.getElementsByTagName("script")[0];
            s.parentNode.insertBefore(hm, s);
        })();
    </script>
</body>
<style>
body {
  background-color: #eee;
  overflow: hidden;
}
canvas {
  background-color: #eee;
  display: block;
  margin: 0 auto;
  position: absolute;
  top: 0;
}
.layadmin-user-login{
	z-index: 99;
}
</style>
</html>